package com.wzq.app.ui.widget;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by jgzheng on 2016/7/5.
 * catch exception: Android java.lang.IllegalArgumentException: pointerIndex out of range
 */
public class CatchableViewPager extends ViewPager {
    private boolean isScroll = true;

    public CatchableViewPager(Context context) {
        super(context);
    }

    public CatchableViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    public void isScroll(boolean isScroll) {
        this.isScroll = isScroll;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (!isScroll) {
            return false;
        }
        try {
            return super.onInterceptTouchEvent(ev);
        } catch (IllegalArgumentException ex) {
        }
        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        try {
            return super.onTouchEvent(ev);
        } catch (IllegalArgumentException ex) {

        }

        return false;
    }
}
